home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM 1
/
LIGHT-ROM 1 (Amiga Library Services)(1994).iso
/
ffdisks
/
d939.lha
/
ExtraCmds
/
source_etc.lha
/
src
/
Copyright.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
4KB
|
177 lines
/* --------------------------------- -------
* |\ | | | | | |.| | \| |/ /|\ |||||||
* | | | |/ | |\ |/ |/| |\ |/ | ? ---+--- =<
* | | | | | | | | | | | \qqqqqqqqq/
* --------------------------------- ~~~~~~~~~~~~~~~~
* COPYRIGHT - Prints embedded copyright messages
* Copyright (C) 1993 Torsten Poulin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* The author can be contacted by s-mail at
* Torsten Poulin
* Banebrinken 99, 2, 77
* DK-2400 Copenhagen NV
* DENMARK
*
* $Id: Copyright.c,v 37.3 93/03/01 12:51:16 Torsten Rel $
* $Log: Copyright.c,v $
* Revision 37.3 93/03/01 12:51:16 Torsten
* Changed all occurrences of "struct DosBase *" to "struct DosLibrary *"
*
* Revision 37.2 93/02/24 19:00:33 Torsten
* Restructured the code.
* Template is now FILE/M/A.
* Understands patterns.
* Prints a header before each message.
*
* Revision 37.1 93/02/07 11:43:43 Torsten
* This is the initial revision.
*
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#ifdef __SASC
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#endif
#include "tastlib.h"
#include "copyright_rev.h"
#define PROGNAME "Copyright"
#define TEMPLATE "FILE/M/A"
#define OPT_FILE 0
char const versionID[] = VERSTAG;
char const copyright[] = "$COPYRIGHT:Copyright © 1993 Torsten Poulin$";
typedef struct {
struct DosLibrary *DOSBase;
} Global;
BOOL match(BPTR fp, char *s, Global *global);
LONG scan(UBYTE *filename, Global *global);
LONG entrypoint(VOID)
{
struct DosLibrary *DOSBase;
struct RDArgs *args;
Global *global;
LONG arg[1];
LONG rc = RETURN_OK;
if (!(DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37L)))
return RETURN_FAIL;
if (!(global = AllocVec(sizeof(Global), MEMF_PUBLIC | MEMF_CLEAR)))
{
PrintFault(ERROR_NO_FREE_STORE, PROGNAME);
rc = RETURN_FAIL;
}
else
{
global->DOSBase = DOSBase;
arg[OPT_FILE] = 0L;
if (!(args = ReadArgs(TEMPLATE, arg, NULL)))
{
printerror(PROGNAME, global);
rc = RETURN_ERROR;
}
else
{
rc = foreach((UBYTE **) arg[OPT_FILE], scan, global);
FreeArgs(args);
if (rc == ERROR_BREAK)
{
PrintFault(ERROR_BREAK, NULL);
rc = RETURN_WARN;
}
else if (rc == ERROR_NO_FREE_STORE)
{
PrintFault(ERROR_NO_FREE_STORE, PROGNAME);
rc = RETURN_FAIL;
}
else if (rc != RETURN_OK)
printerror(PROGNAME, global);
}
FreeVec(global);
}
CloseLibrary((struct Library *) DOSBase);
return rc;
}
BOOL match(BPTR fp, char *s, Global *global)
{
struct DosLibrary *DOSBase = global->DOSBase;
LONG c;
while (*s == (c = FGetC(fp)) && c != EOF)
{
s++;
if (!*s)
return TRUE;
}
if (c != EOF)
UnGetC(fp, c);
return FALSE;
}
LONG scan(UBYTE *filename, Global *global)
{
struct DosLibrary *DOSBase = global->DOSBase;
LONG c;
BPTR fp;
BPTR out = Output();
LONG rc = RETURN_OK;
if (!(fp = Open(filename, MODE_OLDFILE)))
{
printerror(PROGNAME, global);
rc = RETURN_ERROR;
}
else
{
while ((c = FGetC(fp)) != EOF)
{
if (c == '$')
if(match(fp, "COPYRIGHT:", global))
{
PutStr(filename);
PutStr(" contains the following message:\n");
/* skip leading blanks */
while ((c = FGetC(fp)) != EOF && c == ' ')
;
UnGetC(fp, c);
while ((c = FGetC(fp)) != EOF && c != '\0' && c != '$')
FPutC(out, c);
FPutC(out, '\n');
break;
}
}
Close(fp);
}
return rc;
}